//
//  FaHuoViewController.m
//  jingdongfang
//
//  Created by mac on 16/11/3.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "FaHuoViewController.h"
#import "IGShipApi.h"

@interface FaHuoViewController ()
@property (weak, nonatomic) IBOutlet UITextField *codeLab;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property(nonatomic,strong)IGShipApi *shipApi;
@property (strong, nonatomic) IBOutlet UIButton *sendBtn;

@end

@implementation FaHuoViewController
#pragma mark -生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.navigationItem.title = @"发货";
    self.navigationItem.title = NSLocalizedString(@"Shipped", nil);
    
    
    UITapGestureRecognizer * tap  =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    [_bgView addGestureRecognizer:tap];

}
#pragma mark -发货
- (IBAction)submintBtnAction:(id)sender {
    
    NSString * order_type = _nameTextField.text;
    NSString * state_order = _codeLab.text;
    
    self.sendBtn.enabled =NO;
    [self performSelector:@selector(changeButtonStatus) withObject:nil afterDelay:1.0f];//防止重复点击
    if (order_type.length == 0) {
//        [self showErrorText:@"请输入快递公司名称"];
        [self showErrorText:NSLocalizedString(@"Please fill in the shipping company name", nil)];
        return;
        _sendBtn.enabled =YES;
    }
    if (state_order.length == 0) {
//        [self showErrorText:@"请输入快递单号"];
        [self showErrorText:NSLocalizedString(@"Please provide tracking number", nil)];
        return;
        _sendBtn.enabled =YES;
    }
    self.shipApi=[[IGShipApi alloc]initWithOid:self.o_id orderType:order_type expressOrder:state_order];
    [self.shipApi startWithDecodeClass:[IGShipResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
//             [self presentMessageTips:@"发货成功!"];
            [self presentMessageTips:NSLocalizedString(@"Delivery Successful", nil)];
            [self .navigationController popViewControllerAnimated:YES];
        }
    }];
}

-(void)changeButtonStatus{
    self.sendBtn.enabled =YES;
}

- (void)tapAction{
    
    [self.view endEditing:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
